--编写者：
--功能介绍：选完角色装备指定物品
--使用方法：直接粘贴到模组环境 修改prefablist specialinit

local prefablist = {
    wes = { "handpillow_steelwool", "yellowamulet", "nightcaphat" },
}
local specialinit = {
    yellowamulet = function(inst)
        inst:RemoveComponent("fueled")
    end,
}
AddPrefabPostInit("world", function(world)
    if not TheWorld.ismastersim then
        return
    end
    world:ListenForEvent("ms_newplayerspawned", function(_, player)
        local prefab = player.prefab
        if prefab and prefablist[prefab] then
            for kk, vv in pairs(prefablist[prefab]) do
                local aplayer_inv = player.components.inventory
                local aitem = SpawnPrefab(vv)
                if aitem and specialinit[vv] then
                    specialinit[vv](aitem)
                end
                if aitem then
                    aplayer_inv:Equip(aitem)
                end
            end
        end
    end)
end)
--[[ for k, v in pairs(prefablist) do
    AddPrefabPostInit(k, function(inst)
        if not TheWorld.ismastersim then
            return inst
        end
        inst:DoTaskInTime(1, function(inst)
             --装备钢丝绵枕头
            local aplayer_inv = inst.components.inventory
            local aitem = SpawnPrefab("handpillow_steelwool")
            local aslot = aitem.components.equippable.equipslot
            local aold_item = aplayer_inv:GetEquippedItem(aslot)
            aplayer_inv:RemoveItem(aold_item, true)
            if aold_item then
                aold_item:Remove()
            end
            aplayer_inv:Equip(aitem)
            --装备魔光
            local bplayer_inv = inst.components.inventory
            local bitem = SpawnPrefab("yellowamulet")
            bitem:RemoveComponent("fueled") --移除耐久组件
            local bslot = bitem.components.equippable.equipslot
            local bold_item = bplayer_inv:GetEquippedItem(bslot)
            bplayer_inv:RemoveItem(bold_item, true)
            if bold_item then
                bold_item:Remove()
            end
            bplayer_inv:Equip(bitem)
            --装备睡帽
            local cplayer_inv = inst.components.inventory
            local citem = SpawnPrefab("nightcaphat")
            local cslot = citem.components.equippable.equipslot
            local cold_item = cplayer_inv:GetEquippedItem(cslot)
            cplayer_inv:RemoveItem(cold_item, true)
            if cold_item then
                cold_item:Remove()
            end
            cplayer_inv:Equip(citem)
        end)
    end)
end ]]
